using System;
using System.Linq;
using TimeMachine.Engine.Vcs;

namespace TimeMachine.Engine.Metrics.Impl
{
	public abstract class FilesOperationsMetric : BaseMetric
	{
		private readonly Func<FileChangeInfo, bool> isAcceptable;
		private readonly ICommitsInfoProvider commitsProvider;

		protected FilesOperationsMetric(ICommitsInfoProvider commitsProvider, Func<FileChangeInfo, bool> isAcceptable)
		{
			this.commitsProvider = commitsProvider;
			this.isAcceptable = isAcceptable;
		}

		public override MetricValue Calculate(int rev)
		{
			int value = commitsProvider.Get(rev).Changes.Count(isAcceptable);
			return new MetricValue(rev, Desc.MetricId, value);
		}

		public override IAggregator CreateAggregator()
		{
			return new SumPerDay();
		}
	}
}